package com.bjc.sdx.activity;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.bjc.sdx.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class SimpleAdapterActivity extends Activity {
    ListView lv_man;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.lv_man);//加载(是布局不是id!)
        lv_man=(ListView) findViewById(R.id.lv_man);//获取操作
        ArrayList<Map<String, Object>> arrayList = new ArrayList<Map<String,Object>>();
        //new了一个Arraylist数组包含map集合
        HashMap<String, Object> hashMap = new HashMap<String, Object>();
        //new了一个map集合编写key value
        hashMap=new HashMap<String, Object>();
        //简写用上面hashMap的对象再新建一个map集合,赋值,添加到arrayList集合中
        hashMap.put("icom", R.drawable.apple);
        hashMap.put("name","美食--2");
        hashMap.put("content","内容");
        arrayList.add(hashMap);

        hashMap=new HashMap<String, Object>();
        hashMap.put("icom", R.drawable.gril);
        hashMap.put("name","美食--3");
        hashMap.put("content","内容");
        arrayList.add(hashMap);

        hashMap=new HashMap<String, Object>();
        hashMap.put("icom", R.drawable.banana);
        hashMap.put("name","美食--4");
        hashMap.put("content","内容");
        arrayList.add(hashMap);

        hashMap=new HashMap<String, Object>();
        hashMap.put("icom", R.drawable.strawberry);
        hashMap.put("name","美食--5");
        hashMap.put("content","内容");
        arrayList.add(hashMap);

        hashMap=new HashMap<String, Object>();
        hashMap.put("icom", R.drawable.ic_baseline_star_24);
        hashMap.put("name","美食--6");
        hashMap.put("content","内容");
        arrayList.add(hashMap);

        hashMap=new HashMap<String, Object>();
        hashMap.put("icom", R.drawable.baidu_cloud);
        hashMap.put("name","美食--7");
        hashMap.put("content","内容");
        arrayList.add(hashMap);

        arrayList.add(hashMap);
        //arrayList集合里面有许多个map集合,map集合中有许多的数据
//      Map对象中的key的数组,用于得到对应的value
        String from[]={"icom","name","content"};//定义from代表map里面的key值
//      item布局文件中的子View的id的数组
        int [] to ={R.id.imageView1,R.id.tv_item_name,R.id.tv_item_content,};
        //定义to代表布局控件
//      准备SimpleA
        SimpleAdapter simpleAdapter = new SimpleAdapter(this, arrayList,
                R.layout.lv_child, from, to);
        //加载包含to的控件视图(不是视图id),from是通过key获取了value值,
//      to是把value赋给了布局中的控件
        lv_man.setAdapter(simpleAdapter);
//      设置适配器
    }
}
